package com.gopay.common.cps.manager.trans.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import com.gopay.common.cps.dao.trans.AcctTransDAO;
import com.gopay.common.cps.manager.trans.AcctTransManager;
import com.gopay.common.domain.acps.AcpsAcctTransDtl;
import com.gopay.common.domain.acps.PstdFlag;

/**
 * 账务明细查询Manager实现
 * 
 * @AcctTransManagerImpl.java
 * @author yaobo
 * @2013-7-9 下午05:12:33 www.gopay.com.cn Inc.All rights reserved.
 */
@Service("acctTransManager")
public class AcctTransManagerImpl implements AcctTransManager {
    @Resource(name = "acctTransDAO")
    private AcctTransDAO acctTransDao;

    @Override
    public List<AcpsAcctTransDtl> getAcctTransDtls(String gopayOrderId, String drOrCr) {
        return acctTransDao.getAcctTransDtls(gopayOrderId, drOrCr);
    }

    @Override
    public List<AcpsAcctTransDtl> getAcctTransDtlsByTimeInterval(Date startDate, Date endDate, int pageIndex,
            int pageSize) {
        DetachedCriteria criteria = DetachedCriteria.forClass(AcpsAcctTransDtl.class);
        criteria.add(Restrictions.between("tranTime", startDate, endDate));
        criteria.add(Restrictions.eq("pstdFlg", PstdFlag.Y));
        List<AcpsAcctTransDtl> list = acctTransDao.findByCriteria(criteria, pageIndex, pageSize);
        return list;
    }

    @Override
    public int getAcctTransCountByTimeInterval(Date startDate, Date endDate) {
        DetachedCriteria criteria = DetachedCriteria.forClass(AcpsAcctTransDtl.class);
        criteria.add(Restrictions.eq("pstdFlg", PstdFlag.Y));
        criteria.add(Restrictions.between("tranTime", startDate, endDate));
        return acctTransDao.findCountByCriteria(criteria);

    }
}
